package com.bite.book.aspect;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-06-09
 * Time:21:07
 */
@Slf4j//日志
@Component//被Spring使用
@Aspect//标识这是一个切面类，用来处理某一类特定问题
/*记录耗时*/
public class TimeRecordAspect {
    @Around("execution(* com.bite.book.controller.*.*(..))")
    public Object timeRecord(ProceedingJoinPoint joinPoint) throws Throwable {
        //记录开始时间
        long start=System.currentTimeMillis();
        //执行目标方法
        Object proceed = joinPoint.proceed();
        //记录结束时间
        long end=System.currentTimeMillis();
        //日志打印耗时
        log.info("耗时时间："+(end-start)+"ms");
        //返回
        return proceed;
    }
}
